#import "SEGUserauthManager.h"

#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif

#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

static id _UserAuthManager;
static dispatch_once_t onceToken;

@implementation SEGUserauthManager
#pragma mark - SINGLE----BEGIN----
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _UserAuthManager = [[self alloc] init];
    });
    return _UserAuthManager;
}

+(void)destroyResource{
    onceToken = 0;
    _UserAuthManager = nil;
}

#pragma mark - SINGLE----END----

#pragma mark - HTTP----BEGIN----
-(void)requestUserauthWithCommunityid:(NSString*)communityId enterpriseId:(NSString*)enterpriseId userType:(NSString*)userType userTel:(NSString*)userTel custName:(NSString*)custName imagePath:(NSString*)imagePath finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:communityId forKey:@"communityId"];
    [params setValue:enterpriseId forKey:@"enterpriseId"];
    [params setValue:userType forKey:@"userType"];
    [params setValue:custName forKey:@"custName"];
    [params setValue:userTel forKey:@"userTel"];
    if (imagePath && imagePath.length >0) {
        [params setValue:imagePath forKey:@"imagePath"];
    }
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/enterprise-app/user/auth",nil];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        self.UserAuth = [SEGUserauthModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
//    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
//        if (!isSuccessed) {
//            finished(isSuccessed,nil,codeType,error.localizedDescription);
//            return;
//        }
//
//        self.UserAuth = [SEGUserauthModel yy_modelWithDictionary:result];
//        finished(isSuccessed,result,codeType,error.localizedDescription);
//        return;
//    }];
}
#pragma mark - HTTP----END----

#pragma mark - GETTER----BEGIN----
-(SEGUserauthModel *)UserAuth{
    if (!_UserAuth) {
        _UserAuth = [[SEGUserauthModel alloc]init];
    }
    return _UserAuth;
}
#pragma mark - GETTER----END----
@end

